<?php
/**
 * Created by JetBrains PhpStorm.
 * User: scala
 * Date: 12-10-23
 * Time: 下午1:33
 * To change this template use File | Settings | File Templates.
 */
class StaffAction extends Action
{

    function index(){
        $article=M("StaffArticle");
        import("ORG.Util.Page");// 导入分页类
        $count=$article->count();
        $Page= new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
        $Page->setConfigArray(array('header'=>'篇员工软文','prev'=>'<input type="button" value="<<">','next'=>'<input type="button" value=">>">','first'=>'首页','last'=>'尾页','theme'=>' %totalRow% %header% %nowPage%/%totalPage% 页   %first% %prePage% %upPage%   <span style="color: red;">%linkPage%</span>   %downPage% %nextPage% %end%'));
        $show=$Page->show();//分页显示输出
        $list=$article->limit($Page->firstRow.",".$Page->listRows)->order("createtime desc")->select();
        $this->assign("list",$list);
        $this->assign('page',$show);// 赋值分页输出\
        $user=M("User");
        $userList=$user->select();
        $this->assign("userList",$userList);
		
		$news=M("News");
        $newsList=$news->order('id desc')->limit('0,3')->select();
        $this->assign("newsList",$newsList);
		
        $this->display();
    }

    function details(){
        if(!empty($_GET['id'])){
            $article=M("StaffArticle");
            $list=$article->find($_GET['id']);
            $user=M("User");
            $userList=$user->find($list['author']);
            $this->assign("userList",$userList);
            $this->assign("list",$list);
			
			$news=M("News");
			$newsList=$news->order('id desc')->limit('0,3')->select();
			$this->assign("newsList",$newsList);

            //上一篇

            $front=$article->where("id<".$list['id'])->order('id desc')->limit('1')->find();
            $f=!$front?'没有了':'<a href="__URL__/details/id/'.$front['id'].'">'.$front['title'].'</a>';
            $this->assign('front',$f);

            //下一篇

            $after=$article->where("id>".$list['id'])->order('id asc')->limit('1')->find();
            $a=!$after?'没有了':'<a href="__URL__/details/id/'.$after['id'].'">'.$after['title'].'</a>';
            $this->assign('after',$a);
        }
        $this->display();
    }

}
